package com.chezhujie.www.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chezhujie.www.domain.ImSMSstorage;
import com.chezhujie.www.persistence.ImSMSstorageMapper;
import com.sys.core.exception.ClassCheckException;
import com.sys.user.base.service.BaseService;


/**
 * 短信入库
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class ImSMSstorageService extends BaseService<ImSMSstorage>{
    @Autowired
    private ImSMSstorageMapper imsmsstorageMapper;

    @Autowired
    public void setBaseMapper(ImSMSstorageMapper imsmsstorageMapper) {
        this.baseMapper = imsmsstorageMapper;
    }


    public void checkEntity(ImSMSstorage imsmsstorage) throws ClassCheckException {
        if(imsmsstorage.getSmsstorageId()!=null&&imsmsstorage.getSmsstorageId().length()>19){
            throw new ClassCheckException("短信入库主键不能超过19个字符");
        }
        if(imsmsstorage.getMobile()!=null&&imsmsstorage.getMobile().length()>50){
            throw new ClassCheckException("短信入库手机号码不能超过50个字符");
        }
        if(imsmsstorage.getSendid()!=null&&imsmsstorage.getSendid().length()>50){
            throw new ClassCheckException("短信入库短信发送接口返回的sendid不能超过50个字符");
        }
        if(imsmsstorage.getResult()!=null&&imsmsstorage.getResult().length()>255){
            throw new ClassCheckException("短信入库运营商返回的短信发送状态码不能超过255个字符");
        }
        if(imsmsstorage.getSendTime()!=null&&imsmsstorage.getSendTime().length()>250){
            throw new ClassCheckException("短信入库短信发送时间，调用sms-api接口发送短信的时间不能超过250个字符");
        }
        if(imsmsstorage.getReportTime()!=null&&imsmsstorage.getReportTime().length()>250){
            throw new ClassCheckException("短信入库运营商返回的短信送达时间 不能超过250个字符");
        }
        if(imsmsstorage.getSpliced()!=null&&imsmsstorage.getSpliced().length()>250){
            throw new ClassCheckException("短信入库短信计费条数不能超过250个字符");
        }
    }
    public void checkListEntity(List<ImSMSstorage> listImSMSstorage) throws ClassCheckException {

        for (ImSMSstorage imsmsstorage : listImSMSstorage) {
            checkEntity(imsmsstorage);
        }

    }
}
